<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Setea los mensajes de error.
 * 
 */
if (!function_exists('set_message')) {

    function set_message($array_message) {
        $ci = & get_instance();

        $type = array();
        $message = array();
        foreach ($array_message as $key => $value) {
            switch ($key) {
                case 1:
                    $key = 'success';
                    break;

                case 2:
                    $key = 'block';
                    break;

                case 3:
                    $key = 'error';
                    break;

                case 4:
                    $key = 'info';

                default:
                    $key = 'info';
                    break;
            }
            $type[] = $key;
            $message[] = $value;
        }

        $ci->session->set_userdata('msg_type', $type);
        $ci->session->set_userdata('msg_message', $message);
    }

}

/**
 * Devuelve los mensajes de error.
 * 
 */
if (!function_exists('get_message')) {

    function get_message() {
        $ci = & get_instance();

        $type = $ci->session->userdata('msg_type');
        $message = $ci->session->userdata('msg_message');

        if (!empty($type)) {
            $top = count($type);
            for ($i = 0; $i < $top; $i++) {
                ?>
                <div class="alert alert-<?php echo $type[$i] ?>">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <?php echo $message[$i] ?>
                </div>
                <?php
            }
        }
        $ci->session->unset_userdata('msg_type');
        $ci->session->unset_userdata('msg_message');
    }

}
